package com.eduhzy.ttw.commonsdk.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;

import java.util.List;

/**
 *
 * @author xubo
 */
public class HomeFragmentAdapter extends FragmentStatePagerAdapter {
    private final List mTitles;
    private final List mFragments;

    @Override
    public int getCount() {
        return this.mTitles.size();
    }

    @Override
    public Fragment getItem(int position) {
        return (Fragment) this.mFragments.get(position);
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return (CharSequence) this.mTitles.get(position);
    }

    public HomeFragmentAdapter(FragmentManager fm, List mTitles, List mFragments) {
        super(fm);
        this.mTitles = mTitles;
        this.mFragments = mFragments;
    }
    // 动态设置我们标题的方法
    public void setPageTitle(int position, String title)
    {
        if(position >= 0 && position < mTitles.size())
        {
            mTitles.set(position, title);
            notifyDataSetChanged();
        }
    }
}
